<link type="text/css" rel="stylesheet" href="<{$config.weburl}>/module/product/templates/pro.css">
<script src="<{$config.weburl}>/script/jquery.imagezoom.min.js" type="text/javascript"></script>
<script type="text/javascript">
function collect_goods(){
	
	var url = '<{$config.weburl}>/module/sns/ajax_update.php';
	var uname='<{$smarty.cookies.USER}>';
	if(uname=='')
	{
		alert('<{$lang.no_logo}>');
		window.location.href='<{$config.weburl}>/login.php?forward='+encodeURIComponent("index.php/?m=product&s=detail&id=<{$smarty.get.id}>");
		return false;
	}
	id=$('#sid').val();
	if(id!=0)
	{
		var pars = 'pid='+id+'&uname='+uname;
		$.post(url, pars,showResponse);
	}
	function showResponse(originalRequest)
	{
		if(originalRequest>1)
			alert('<{$lang.fav_ok}>');
		else if (originalRequest>0)
			alert('<{$lang.fav_isbing}>');
		else
			alert('<{$lang.error}>');
	}
}
function buy()
{
	var B = false;
	$('ul[data_type="property"]').each(function(){

		if(!$(this).find('a').hasClass('checked')){
	        B = true;
		}
	});

	if (goodsspec.getSpec() == null || B)
    {
        alert('请选择相关规格');
        return !B;
    }
	else
	{
		return !B;	
	}
}
</script>
<div class="w">
    <div class="detailnav">
        <{foreach item=list key=key from=$catname}>
        <{if $key==0}>
        <strong><a href="?m=product&s=list&id=<{$list}>"><{$list|getName}></a></strong><span>
        <{else}>
         > <a href="?m=product&s=list&id=<{$list}>"><{$list|getName}></a>
        <{/if}>
        <{/foreach}>
        <{if $de.brand}>
         > <a href="?m=product&s=list&brand=<{$de.brand}>"><{$de.brand}></a>
        <{/if}>
         > <a href="?m=product&s=detail&id=<{$de.id}>"><{$de.ftitle}></a>
        </span>
    </div>
</div>
<div class="w">
	<div class="product_intro">
       	<div class="product_name">
        	<h1 title="<{$de.pname}>"><{$de.pname}></h1>
            <{if $de.promotion_tips}><strong title="<{$de.promotion_tips}>"><{$de.promotion_tips}></strong><{/if}>
        </div>
        <ul class="product_info clearfix">
        	<{if $de.market_price!='0.00'}>
            <li><div class="dt">参 考 价:</div><div class="dd"><s><{$config.money}><{$de.market_price}></s></div></li>
            <{/if}>
            <li><div class="dt">销 售 价:</div><div class="dd"><strong class="p-price"><{$config.money}><{$de.price}></strong></div></li>
            <li>
            <div class="dt">产品评分:</div>
            <div class="dd star"><span class="star" style="width:<{$de.good}>% "></span></div>
            <div class="count">(已有<{$de.count}>人评价)</div>
            </li>
            <li><div class="dt">配 送 至:</div><div class="dd"><span><{$de.user_ip}></span></div></li>
            <li><div class="dt">服　　务:</div><div class="dd"><span>由 <{if $de.shop_name}><{$de.shop_name}><{else}><{$config.company}><{/if}> 发货并提供售后服务。</span></div></li>
            <{if $de.product_gives}>
			<li>
                <div class="dt">赠　　品:</div>
                <div class="dd">
               	<{foreach item=list key=key from=$de.product_gives}>
                    <div class="li-img<{if $key==0}> mt0<{/if}> "><img width="25" height="25" src="<{$list.pic}>_60X60.jpg"><{$list.pname}><em> × 1</em></div>
                <{/foreach}>
                </div>
            </li>
            <{/if}>
        </ul>
        
        <{if $de.porperty}>
        <div class="select_style clearfix">
            <{foreach item=list from=$de.extfiled.d}>
                <{$list}>
            <{/foreach}>
        <{if !$de.service}></div><{/if}>
        <{/if}>
        
        <{if $de.service}>  
        <{if !$de.porperty}><div class="select_style clearfix"><{/if}>
        <dl id="service"><dt>服务:</dt>
        <dd>
            <ul>
                <{foreach item=list from=$de.service}>
                <li title="<{$list.name}>"><a data-param="{'service_id':'<{$list.id}>'}" onclick="selectSpec('0',this,'0',false);"><{$list.name}><i></i></a></li>
                <{/foreach}>
            </ul>
        </dd>
        </dl>
        </div>
        <{/if}>
        
        <form onsubmit="return buy()" action="<{$config.weburl}>/?m=product&s=shop_cart" method="post">
        <div class="choose_amount clearfix">
        	<div class="dt">购买数量:</div>
            <div class="dd">
                <a id="low_num" class="low_num" href="javascript:;">-</a>
                <input onkeyup="check_nums();" maxlength="3" name="nums" class="nums" id="nums" type="text" value="1" />
                <a id="add_num" class="add_num" href="javascript:;">+</a>
                &nbsp;(<{$lang.stock}><span id="stock"><{$de.amount}></span><{$lang.item}>)
            </div>
        </div>
        <{if $de.porperty}><div class="choose_result"></div><{/if}>
        <div class="choose_button clearfix">
        <input name="service" id="hidden_service" type="hidden" value="0," />
        <input name="id" id="sid" type="hidden" value="<{$de.id}>" />
		<input type="image" id="addcart_submit" class="buy" src="<{$config.weburl}>/image/default/buy.png" />
        <a href="javascript:collect_goods();">收藏</a>
        </div>
        </form>
        <div id="preview">
            <div id="imgmove">  
            	<a title="zoom" href="<{if $de.pic}><{$de.pic}><{else}>image/default/nopic.gif<{/if}>">  
                <{if $de.pic}>
                <{assign var=img value=$de.pic}>
                <{else}>
                <{assign var=img value='image/default/nopic.gif'}>
                <{/if}>
            	<img class="jqzoom" alt="<{$de.pname}>" rel="<{$img}>" src="<{$img}>" title="<{$de.pname}>">
                </a>
            </div>
			<div id="jqzoom" class="spec_list">         
                <ul>
                <{foreach item=pic key=num from=$de.pic_more}>
                    <li class="fore<{$num+1}><{if $num==0}> ml0<{/if}>" >
                    <img <{if $num==0}>class="img-hover"<{/if}> src="<{$pic}>_60X60.jpg" big="<{$pic}>" width="50">
                    </li>
                <{/foreach}>
                </ul>
			</div>
        </div>
    </div>
</div>
<{if $de.product_related }>
    <div class="w">
    	<div class="related">
        	<div class="mt"><h2>其它类似商品</h2></div>
            <div class="mc clearfix">
    		<ul><{insert name="label" type="product" setmeal=1 product_id=$de.product_related orderby=rand temp="product_list_li" limit=5}></ul>
    		</div>
        </div>
    </div>
<{/if}>
<div class="w">
    <div class="right">
    	<div class="product_detail">
        	<{if $de.product_partss }>
            <div class="match clearfix">
                <div class="product_detaila_title">
                    <div class="mt">
                        <ul>
                            <li class="curr" tabindex="0"><a href="javascript:;">推荐配件</a></li>
                        </ul>
                    </div>
                </div>
                <form id="forms" method="post" action="<{$config.weburl}>/?m=product&s=shop_cart">
                <input type="hidden" name="act" value="match" />
                <input name="nums" type="hidden" value="1" />
                <input name="id" id="sid1" type="hidden" value="<{$de.id}>" />
        		<input name="service" id="service1" type="hidden" value="0," />
                <div class="i-mc clearfix">
                 	<div class="clearfix">
                        <div class="master">
                            <s></s>
                        	<div class="i-master">
                                <div class="p-img"><img width="130" height="130" src="<{$de.pic}>" /></div>
                                <div class="p-name"><{$de.pname}></div>    
                                <div class="p-price"><{$config.money}><{$de.price}></div>
							</div>			                            
                        </div>
                        <div class="suits">
                        <{assign var=count value=$de.product_partss|@count}>
                        <ul style="width:<{$count*145}>px">
                            <{foreach item=list from=$de.product_partss}>
                                <li>
                                    <div class="p-img"><a target="_blank" href="<{$config.weburl}>/?m=product&s=detail&id=<{$list.id}>"><img width="130" height="130" src="<{$list.pic}>" /></a></div>
                                    <div class="p-name"><a target="_blank" href="<{$config.weburl}>/?m=product&s=detail&id=<{$list.id}>"><{$list.pname}></a></div>    
                                    <div class="p-price">
                                    <input onclick="sum('<{$list.id}>')" class="fl chk" type="checkbox" value="<{$list.id}>" id="chk_<{$list.id}>" name="chk[<{$list.id}>]" />
                                    <label for="chk_<{$list.id}>" class="fl"><{$config.money}><span id="price_<{$list.id}>"><{$list.price}></span></label>
                                    </div>
                                </li>
                            <{/foreach}>
                        </ul>
                        </div>
                    </div>
                    <div class="sum clearfix">
                        <div class="fr">
                            <div class="btns"><a class="btn-buy">立刻购买</a></div>
                            <span class="price"><{$config.money}><em id="prices"><{$de.price}></em></span>
                            <span>套餐价：</span>
                        </div>
                    </div>
                </div>
                </form>
            </div>
			<script>
            function sum(id)
            {
                flag=buy();
                if(flag)
                {
                    checked=$("#chk_" + id).attr("checked");
                    aa=$("#price_"+id).html();
                    bb=$("#prices").html();
                    bb=bb.replace(",",""); 
                    if(checked==true)
                    {
                        cc=parseInt(aa)+parseInt(bb);
                        $("#prices").html(cc.toFixed(2));
                    }
                    else
                    {
                        cc=parseInt(bb)-parseInt(aa);
                        $("#prices").html(cc.toFixed(2));
                    }
                }
                else
                {
                    checked=$("#chk_" + id).attr("checked","");	
                }
            }
            $('.btn-buy').click(function(){
                $("#forms").submit();
            });
            </script>
            <{/if}>
            <div class="product_detaila_title">
            	<div class="mt">
                	<ul>
                    	<li class="curr"><a href="javascript:;">商品介绍</a></li>
                        <{if $de.extfiled.p}>
                        <li><a href="javascript:;">规格参数</a></li>
                        <{/if}>
                        <li><a href="javascript:;">商品评价</a></li>
                    	<li><a href="javascript:;">售后保障</a></li>
                    </ul>
                </div>
            </div>
            <div class="product_detaila_content">
            	<ul class="detail_list clearfix">
                	<li>产品名称：<{$de.ftitle}></li>
    				<li>产品编号：<{$de.code}></li>
                    <li>品牌：<{$de.brand}></li>
                    <li>上架时间：<{$de.uptime}></li>
                    <{foreach item=list from=$de.extfiled.s}>
                    	<{$list}>
                    <{/foreach}>
                </ul>
            	<div class="detail_content"><{$de.detail}></div>
            </div>
            <{if $de.extfiled.p}>
            <div class="product_detaila_content hidden">
            <table width="100%" cellpadding="0" cellspacing="1" class="parameter">
                <{foreach item=list key=key from=$de.extfiled.p}>
                    <tr><th colspan="2"><{$key}></th></tr>
                    <{foreach item=slist from=$list}>
                    	<{$slist}>
                    <{/foreach}>
                <{/foreach}>
            </table>    
            </div>
            <{/if}>
            <div class="product_detaila_content" style="display:none;">
                <div class="mc">
                    <div class="rate clearfix">
                       <span>好评度</span>
                       <strong class="clearfix"><{$de.good}><em>%</em></strong>
                    </div>
                    <div class="percent">
                        <dl>
                            <dt>好评<span>(<{$de.good}>%)</span></dt>
                            <dd><div style="width:<{$de.good}>%;"></div></dd>
                        </dl>
                        <dl>
                            <dt>中评<span>(<{$de.middle}>%)</span></dt>
                            <dd><div style="width:<{$de.middle}>%;"></div></dd>
                        </dl>
                        <dl>
                            <dt>差评<span>(<{$de.bad}>%)</span></dt>
                            <dd><div style="width:<{$de.bad}>%;"></div></dd>
                        </dl>
                    </div> 
                    <div class="btns">
                        <div>您可对已购商品进行评价</div>
                        <a target="_blank" class="btn-comment" href="main.php?m=product&s=admin_buyorder&status=4">发评价拿积分</a>
                    </div>
                </div>
                <div class="product_detaila_title">
                    <div class="mt">
                        <ul>
                            <li class="curr"><a href="javascript:;">全部评价</a></li>
                            <li><a href="javascript:;">好评</a></li>
                            <li><a href="javascript:;">中评</a></li>
                            <li><a href="javascript:;">差评</a></li>
                        </ul>
                    </div>
                </div>
                <div class="product_detaila_content comment_list">
                <{insert name="label" type="product_comment" product_id=$de.id limit=5 temp="comment_list_1"}>
                </div>
                <div class="product_detaila_content comment_list hidden">
                <{insert name="label" type="product_comment" product_id=$de.id catid=1 limit=5 temp="comment_list_1"}>
                </div>
                <div class="product_detaila_content comment_list hidden">
                <{insert name="label" type="product_comment" product_id=$de.id catid=0 limit=5 temp="comment_list_1"}>
                </div>
                <div class="product_detaila_content comment_list hidden">
                <{insert name="label" type="product_comment" product_id=$de.id catid='-1' limit=5 temp="comment_list_1"}>
                </div>
            </div>
            <div class="product_detaila_content hidden">
            	<div class="detail_content"><{$de.after_service}></div>
            </div>
		</div>
    	<div class="product_detail mt20">    
            <div class="product_detaila_title">
            	<div class="mt">
                	<ul>
                    	<li class="curr"><a href="javascript:;">全部购买咨询</a></li>
                        <{foreach item=list from=$consultcat}>
                    	<li><a href="javascript:;"><{$list.name}></a></li>
                        <{/foreach}>
					</ul>
                </div>
            </div>
            <div class="consult_search">
            	<div class="fl">
                	<strong>咨询前请选搜索，方便又快捷：</strong>
                    <form method="get" target="_blank">
                    <input type="hidden" name="m" value="<{$smarty.get.m}>">
                    <input type="hidden" name="s" value="consult">
                    <input type="hidden" name="pid" value="<{$smarty.get.id}>">
                    <input type="text" name="k" value="">
                    <input type="image" src="image/default/btn_consult_search.png">
                    </form>
                </div>
                <div class="fr">
                <div><strong>温馨提示:</strong>因厂家更改产品包装、产地或者更换随机附件等没有任何提前通知，且每位咨询者购买情况、提问时间等不同，为此以下回复仅对提问者3天内有效，其他网友仅供参考！若由此给您带来不便请多多谅解，谢谢！</div>
                </div>
            </div>
            <div class="product_detaila_content consult">
                <{insert name="label" type="product_consult" product_id=$de.id limit=5 temp="consult_list_1"}>
				<div class="extra clearfix">
                    <div class="fr"><a target="_blank" href="<{$config.weburl}>?m=product&s=consult&pid=<{$smarty.get.id}>">浏览所有咨询信息&gt;&gt;</a></div>
					<div class="join">购买之前，如有问题，请<a target="_blank" href="<{$config.weburl}>?m=product&s=consult&pid=<{$smarty.get.id}>">咨询</a></div>
                </div>
            </div>
            
            <{foreach item=slist from=$consultcat}>
                <div class="product_detaila_content<{if $slist.type!=1}> consult<{/if}> hidden">
                <{if $slist.type==1}>
                <{$slist.con}>
                <{else}>
				<{insert name="label" type="product_consult" product_id=$de.id catid=$slist.id limit=5 temp="consult_list_1"}>
                <div class="extra clearfix">
                    <div class="fr"><a target="_blank" href="<{$config.weburl}>?m=product&s=consult&pid=<{$smarty.get.id}>">浏览所有咨询信息&gt;&gt;</a></div>
					<div class="join">购买之前，如有问题，请<a target="_blank" href="<{$config.weburl}>?m=product&s=consult&pid=<{$smarty.get.id}>">咨询</a></div>
                </div>
                <{/if}>
                </div>
            <{/foreach}>
        </div>
    </div>
    <div class="left">
        <div class="m">
            <h2>相关分类</h2>
            <ul class="list">
                <{foreach item=list key=num from=$cat}>
                    <li><a href="<{$config.weburl}>?m=product&s=list&catid=<{$list.catid}>"><{$list.cat}></a></li>
                <{/foreach}>
			</ul>
        </div>
        <div class="m">
            <h2>推荐品牌</h2>
            <ul class="list">
                <{foreach item=list key=num from=$brand}>
                    <li><a href="<{$config.weburl}>?m=product&s=list&brand=<{$list.name}>"><{$list.name}></a></li>
                <{/foreach}>
			</ul>
        </div>
        
        <div class="m" id="rank">
        	<h2>热销排行榜</h2>
            <ul class="rankUl clearfix">
            	<li class="cur">同品牌<b></b></li>
            	<li>同分类<b></b></li>
            	<li>同价位<b></b></li>	
            </ul>
            <div class="rankList"  style="display:block">
            	<{insert name="label" type="product" brand=$de.brand catid=$catname.0 limit=5 temp="product_list_1"}>
            </div>
            <div class="rankList">
            	<{insert name="label" type="product" catid=$de.catid catid=$catname.0 limit=5 temp="product_list_1"}>
            </div>
            <div class="rankList">
            	<{insert name="label" type="product" price=$de.price catid=$catname.0 limit=5 temp="product_list_1"}>
            </div>
        </div>
        <div class="ad200">
        <script src='<{$config.weburl}>/api/ad.php?id=13&catid=<{$smarty.get.id}>&name=<{$smarty.get.key}>'></script>
        </div>
    </div>
    <div class="clear"></div>
</div>
<script src="<{$config.weburl}>/script/district_selector.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
	$(".jqzoom").imagezoom();
	$("#jqzoom li").click(function(){
		$(".jqzoom").attr('src',$(this).find("img").attr("big"));
		$(".jqzoom").attr('rel',$(this).find("img").attr("big"));
	});
}); 
$("#low_num").click(function(){
	var num=$('#nums').val()*1;
	if(num>1)
		$('#nums').val(num-1)
});
$("#add_num").click(function(){
	var num=$('#nums').val()*1;
	if(num<$('#stock').html())
		$('#nums').val(num+1)
});
$(".spec_list li").click(function(){
	var t=$(this).find("img");
	var e=t.attr("src");
	$('#imgmove img').attr("src",e.replace("_60X60.jpg",""));
	$(".spec_list img").removeClass("img-hover");
	t.addClass("img-hover");
});
function check_nums() 
{
	var v=document.getElementById('nums').value*1;
	if(!v)
		document.getElementById('nums').value=1;
	if(v>$('#stock').html()*1)
	{
		document.getElementById('nums').value=$('#stock').html()*1;
		return false;
	}
}
<{if $de.extfiled.d || $de.service}>
/* spec对象 */
function spec(id, spec, price, stock, code)
{
	this.id    = id;
	this.spec  = spec;
}
/* goodsspec对象 */
function goodsspec(specs, specQty, defSpec)
{
	this.specs = specs;
	this.specQty = specQty;
	this.defSpec = defSpec;
	<{foreach item=list key=num from=$de.extfiled.d}>
	this.spec<{$num+1}> = null;
	<{/foreach}>
	if (this.specQty >= 1)
	{
		for(var i = 0; i < this.specs.length; i++)
		{
			if (this.specs[i].id == this.defSpec)
			{
					<{foreach item=list key=num from=$de.extfiled.d}>
					this.spec<{$num+1}> = this.specs[i].spec[<{$num}>];
					<{/foreach}>
					break;
			}
		}
	}

	// 取得选中的spec
	this.getSpec = function()
	{
		for (var i = 0; i < this.specs.length; i++)
		{
				<{foreach item=list key=num from=$de.extfiled.d}>
				if (this.specs[i].spec[<{$num}>] != this.spec<{$num+1}>) continue;
				<{/foreach}>
				return this.specs[i];
		}
		return null;
	}

}
/* 选中某规格 num=1,2 */
function selectSpec(num,obj,SID,flag)
{
	flag = flag ? flag : false;
	if(num==0 && SID==0)
	{
		var value=$('#hidden_service').val();
		var data_str = $(obj).attr('data-param');
		eval("data_str = "+data_str);
		
		if($(obj).hasClass("checked"))
		{
			$(obj).removeClass("checked");
			var pattern = ','+data_str.service_id+',';
			str = value.replace(new RegExp(pattern), ",");
			$('#hidden_service').val(str);
			<{if $de.product_partss }>
			$('#service1').val(str);
			<{/if}>
		}
		else
		{
			$(obj).addClass("checked");
			$('#hidden_service').val(value+data_str.service_id+',');
			<{if $de.product_partss }>
			$('#service1').val(value+data_str.service_id+',');
			<{/if}>
		}
	
	}
	else
	{
		goodsspec['spec' + num] = SID;
		$(obj).addClass("checked");
		$(obj).parents('li').siblings().find('a').removeClass("checked");
		var spec = goodsspec.getSpec();
		var sign = 't';
		$('ul[data_type="property"]').each(function(){
			if(!$(this).find('a').hasClass('checked')){
				sign = 'f';
			}
		});
		if (spec != null && sign == 't' && !flag && spec.id!='<{$smarty.get.id}>')
		{
			window.location='?m=product&s=detail&id='+spec.id;
		}
		if (spec != null && sign == 't' && flag)
		{
			var stock="<{if $de.amount}><{$de.amount}><{else}>0<{/if}>";
			
			if(parseInt(stock) == 0){
				$('[class="choose_result"]').show().html('<div class="dd"><em>所选库存量不足，请选择其它购买。</em></div>');
				$('#addcart_submit').attr('disabled',true).css('cursor','pointer');
			}
			else{
				SP_V = '';
				$('ul[data_type="property"]').find('li > .checked').each(function(i){
					SP_V += '<strong>"'+$(this).text()+'"</strong>，';
				});
				SP_V = SP_V.substr(0,SP_V.length-1);
				$('[class="choose_result"]').show().html('<div class="dd"><em>您选择了：</em>'+SP_V+'</div>');
				$('#addcart_submit').attr('disabled',false).css('cursor','auto');
			}
		}
	}
}
<{if $de.porperty }>
var specs = new Array();
<{foreach item=list key=num from=$de.porperty}>
specs.push(new spec(<{$list.id}>, ['<{$list.property_value_id|replace:",":"','"}>']));
<{/foreach}>
var specQty = <{$de.extfiled.d|@count}>;
var defSpec = <{if $de.porperty.0.id}><{$de.porperty.0.id}><{else}>0<{/if}>;
var goodsspec = new goodsspec(specs, specQty, defSpec);
$('ul[data_type="property"]').each(function(){
	if($(this).find('a').hasClass('checked')){
		var data_str = $(this).find('.checked').attr('data_type');
		eval("data_str = "+data_str);
		selectSpec(data_str.num,'',data_str.id,true);
	}
});
<{/if}>
<{/if}>
$(".product_detaila_title li").click(function(){
	
	$(this).addClass("curr").siblings().removeClass("curr");
	var ClassName=$(this).parent().parent().parent().parent().attr('class');
	var index1 = $(this).parent().parent().parent().parent().index();
	var index2 = $(this).index();
	if(ClassName=="product_detaila_content")
	{
		var index0 = $(this).parent().parent().parent().parent().parent().index();
		$(".product_detail").eq(index0).children().eq(index1).children(".product_detaila_content").eq(index2).show().siblings('.product_detaila_content').hide();
	}
	else
	{
		$(".product_detail").eq(index1).children(".product_detaila_content").eq(index2).show().siblings('.product_detaila_content').hide();
	}
	
	
});
saleTopTabSwicth("#rank");
function saleTopTabSwicth(a)
{
	$(a+" li").hover(function(){
		var b=$(a+" li").index($(this));
		$(this).addClass("cur").siblings().removeClass("cur");
		$(a+" .rankList").eq(b).show().siblings(".rankList").hide();
	});
}
</script>